package xyz.thoughtset.viewer.modules.ds.http.core.enums;

import lombok.Getter;

import java.util.Map;

public enum OkHttp3BuilderEnum {
    MAX_IDLE_CONNECTIONS("maxIdleConnections"),
    KEEP_ALIVE_DURATION("keepAliveDuration"),
    PROXY_HOST("proxyHost"),
    PROXY_PORT("proxyPort"),
    PROXY_TYPE("proxyType","HTTP"),
    CONNECT_TIMEOUT("connectTimeout"),
    READ_TIMEOUT("readTimeout"),
    WRITE_TIMEOUT("writeTimeout"),
    ENABLE_VERIFY_SSL("verifySSL","true");

    @Getter
    private final String title;
    private final String defaultValue;
    private final boolean autoLoad;
    
    OkHttp3BuilderEnum(String title) {
        this(title,null);
    }
    OkHttp3BuilderEnum(String title,String defaultValue) {
        this(title,null,false);
    }
    OkHttp3BuilderEnum(String title,String defaultValue,boolean autoLoad) {
        this.title = title;
        this.defaultValue = defaultValue;
        this.autoLoad = autoLoad;
    }

    public static Object getVal(Map map, OkHttp3BuilderEnum builderEnum) {
        Object value = map.get(builderEnum.title);
        if (value == null) {
            value = builderEnum.defaultValue;
        }
        return value;
    }

    public static String getStrVal(Map map, OkHttp3BuilderEnum builderEnum) {
        return (String) getVal(map, builderEnum);
    }

    public static Integer getIntVal(Map map, OkHttp3BuilderEnum builderEnum) {
        Object value = getVal(map, builderEnum);
        return value == null ? null : value instanceof Integer? (Integer) value :Integer.valueOf((String)value);
    }

    public static Long getLongVal(Map map, OkHttp3BuilderEnum builderEnum) {
        Object value = getVal(map, builderEnum);
        return value == null ? null : value instanceof Long? (Long) value :Long.valueOf((String)value);
    }


}
